package com.dingwei.superiordiary.adapter.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.dingwei.superiordiary.R;
import com.dingwei.superiordiary.bean.ChooseBean;
import com.dingwei.superiordiary.bean.CommodityDetailsBean;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.library.flowlayout.FlowLayoutManager;
import com.library.flowlayout.NestedRecyclerView;
import com.library.flowlayout.SpaceItemDecoration;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.utils.DisplayUtil;
import com.lihao.baselibrary.utils.L;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created time 2018/4/1.
 * Creator 南柯一梦丶 on
 * Personal signature 余生还长 何必慌张
 * Page description :
 */

public class TypeAdapter extends RecyclerArrayAdapter<CommodityDetailsBean.DataBean.OptionBeanX> {

    public interface onTypeInterFace {
        void setSize(int position);
    }

    private onTypeInterFace onTypeInterFace;

    public void setOnTypeInterFace(onTypeInterFace listener) {
        onTypeInterFace = listener;

    }


    public TypeAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new TypeHolder(parent);
    }

    class TypeHolder extends BaseViewHolder<CommodityDetailsBean.DataBean.OptionBeanX> {


        @Bind(R.id.tv_name)
        TextView tvName;

        public TypeHolder(ViewGroup parent) {
            super(parent, R.layout.item_size);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void setData(CommodityDetailsBean.DataBean.OptionBeanX data) {
            super.setData(data);

            tvName.setText(data.label);
            if (data.isSelect) {
                tvName.setTextColor(BaseActivity.context.getResources().getColor(R.color.white));
                tvName.setBackground(BaseActivity.context.getResources().getDrawable(R.drawable.theme_select_bg));
            } else {
                tvName.setTextColor(BaseActivity.context.getResources().getColor(R.color.text_color_black));
                tvName.setBackground(BaseActivity.context.getResources().getDrawable(R.drawable.tag_no_select_frame));
            }

            tvName.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (onTypeInterFace!=null){
                        onTypeInterFace.setSize(getDataPosition());
                    }
                }
            });
        }
    }
}
